package com.bk.service;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

@Repository
public class RedisService {

	@Autowired
	private StringRedisTemplate template;

	/*@Autowired
	private Jedis jedis;*/

	public void setKey(String key, String value) {
		ValueOperations<String, String> ops = template.opsForValue();
		ops.set(key, value, (long) (15 * 60), TimeUnit.SECONDS);// 1分钟过期
	}

	public String getValue(String key) {
		ValueOperations<String, String> ops = this.template.opsForValue();
		return ops.get(key);
	}

	public boolean hasRedisKey(String key) {
		return template.hasKey(key) ? true : false;/** 三目 是否有key值 */
	}

	public void deleteRedisByKey(String key) {
		template.delete(key);
	}

	
	public Object getKey(String key) {
		return template.opsForValue().get(key);
	}

	public void delKey(String key) {
		template.delete(key);
	}

	/** set Object *//*
	public String set(String key, String value) {
		return jedis.set(key, value);
	}

	*//** get Object *//*
	public Object get(String key) {
		return jedis.get(key);
	}

	*//** delete a key **//*
	public boolean del(String key) {
		return jedis.del(key.getBytes()) > 0;
	}*/
}
